package com.google.code.sharecontent.test.readmp3;

import java.util.List;

import javax.swing.table.AbstractTableModel;

public class Mp3TableModel extends AbstractTableModel {
	private static final long serialVersionUID = 5567161211619515579L;
	private String[] columnNames = { "FileName","Song Title","Artist","Album","Genre","Identifier","Track","Year","url","Size","ParamDate","ParamLastModified"};

	List<Mp3Info> info;

	public Mp3TableModel(List<Mp3Info> info) {
		super();
		this.info = info;
	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return info.size();
	}

	public String getColumnName(int col) {
		return columnNames[col];
	}

	public Object getValueAt(int row, int col) {
		if (row < this.info.size()) {
			switch (col) {
			case 0:
				return this.info.get(row).getFileName();
			case 1:
				return this.info.get(row).getTitle();
			case 2:
				return this.info.get(row).getArtist();
			case 3:
				return this.info.get(row).getAlbum();
			case 4:
				return this.info.get(row).getGenre();
			case 5:
				return this.info.get(row).getIdentifier();
			case 6:
				return this.info.get(row).getTrack();
			case 7:
				return this.info.get(row).getYear();
			case 8:
				return this.info.get(row).getUrl();
			case 9:
				return this.info.get(row).getSize();
			case 10:
				return this.info.get(row).getParamDate();
			case 11:
				return this.info.get(row).getParamLastModified();
			}
		}
		return "";
	}

	public Class getColumnClass(int c) {
		return String.class;
	}

	public boolean isCellEditable(int row, int col) {
		// Note that the data/cell address is constant,
		// no matter where the cell appears onscreen.
		return false;
	}

	public void setValueAt(Object value, int row, int col) {
		if (row < this.info.size()) {
			switch (col) {
			case 0:
				this.info.get(row).setFileName((String)value);
			}
		}
		fireTableCellUpdated(row, col);

	}

}